The version of Open Prolog to which this document refers is given in the Get Info… information for this document.
Open Prolog is an implementation of Edinburgh-syntax Prolog.
The Edinburgh syntax is the de-facto standard Prolog syntax, and is the basis for the forthcoming ISO Prolog.
If you are an absolute beginner in Open Prolog, it's probably better for you to go through the tutorial session in 'Getting Started'. Then, by all means, read this document carefully, especially the section on workarounds at the end.
This software is continually under development, so it has bugs.
Save your work often.
Changes from previous versions are listed in the file 'Revision History'.
◊ Introduction
Open Prolog is an implementation of Edinburgh-syntax Prolog.
For information on Prolog itself, refer to one of the standard textbooks,
for instance 'Programming in Prolog' by Clocksin & Mellish,
'Introduction to Logic Programming' by Christopher Hogger, or the
excellent 'Artificial Intelligence through Prolog' by Neil C. Rowe.
Open Prolog supports most of the features of DEC Prolog or C-Prolog,
including Definite Clause Grammars.
The 'logical' assert and retract semantics of Lindholm & O'Keefe are
implemented.
Open Prolog supports disjunctive calls, negation, if-then and if-then-else according (we believe) to the draft ISO Prolog standards. In particular, the handling of cuts complies with that specified in the Draft.
It also supports program-originated catch-and-throw exception handling conforming to the ISO Draft.
Real-number arithmetic and internal database predicates are not supported.
Last Call Optimisation (often called Tail Recursion Optimisation) is done,
and indexing on the first argument of clause heads is performed,
mainly to detect determinacy so as to improve memory utilisation.
Open Prolog is called 'Open' because 'external' predicates can be dropped into
it via a Hypercard-like External Predicate Interface.
Open Prolog is not copy protected.
◊ System & Memory Requirements
Open Prolog runs in machines having System 6 or later system software.
It is System 7 compatible, and supports 'required' AppleEvents.
Open Prolog is 32-bit clean, is compatible with RAM Doubler and Speed Doubler.
Open Prolog will run in a memory allocation of
700K bytes or a bit less. 1024K bytes is recommended as a minimum. If you have room,
set it's allocation to 2048K or even 4096K. Do not allocate more memory than your machine really has - for example, if your machine has 8M or RAM, performance will be degraded (especially during garbage collection) if you allocate more than 8M in a machine with virtual memory or RAM Doubler enabled.
Most of the programs you might use or write while you are learning Prolog won't require more than 1024K (1M). If they run out of memory, it's usually due to a programming error. Some large programs do, however, require lots of memory.
Open Prolog has run well in a 16 MB partition (on a Quadra with 20MB RAM, running in 32-bit mode). For your information, it also runs, slowly, in a 48MB partition in the same machine with 80MB virtual memory.
At the other end of the memory scale, Open Prolog will run comfortably under System 6 on a 1MB machine with Multifinder off. If you can't start up in a 1MB machine with Multifinder off, check that you haven't got too big a cache set (64K should be adequate), and/or too many Startup (INIT) Documents, Extensions or Control Panels.
All memory management and garbage collection is automatic.
No divination of stack size or other nonsense is necessary (or possible) - it's done automatically.
The name table is not garbage-collected, so it's possible to overflow it.
Open Prolog is capable of running in the Multifinder/System 7 background
on long computations.
For your information, the development environment is currently a Performa 5300
with System 7.5.1 and Speed Doubler.
◊ Speed
Here are some speeds for the naive reverse benchmark on different Macintoshes:
PowerMac 9500 (120MHz), System 7.5.2 190 KLips
Performa 5300, System 7.5.1, Speed Doubler 130 KLips
Performa LC630, System 7.5.1 60 KLips
Performa 5300, System 7.5.1 25 KLips
PowerBook 140, System 7.5.1 9 KLips
Macintosh Plus, System 7.1 1.9 KLips
It has not been 'tweaked' to perform particularly well on benchmarks.
◊ About Open Prolog…
The 'About Open Prolog…' box contains a stacks indicator which
shows memory space broken into
Name (atom & functor), Code, Global, Local & Trail spaces.
It's possible to watch the stacks grow and contract as the program runs,
but keeping the stacks indicator up-to-date slows execution quite a bit!
To avoid the speed penalty, it's possible to open and close the box while
the interpreter is running.
Alternatively, hiding the stacks indicator fully is just as effective.
On the 'About Open Prolog…' box, you can see how much RAM has been
allocated to Open Prolog. This will be up to a maximum of what was asked
for, but may be much less if there isn't enough memory in the machine.
◊ Installing Open Prolog
Open Prolog can be run from floppy, hard disk, or file server.
It may be in a locked or read-only volume. It requires no special installation.
(Previous versions needed the file Syserrs.Err in the System Folder to provide
error information, but this requirement has been removed. Remove Syserrs.Err
if you no longer need it for other applications.)
When Open Prolog starts up, it looks for a folder called Open Prolog Additions. This folder has to be in the Extensions folder of your System Folder (or just in the System Folder if you're using System 6). If the folder doesn't exist, then Open Prolog will create it. You can place extra stuff for Open Prolog to use in the Open Prolog Additions folder. For example, in this release, there is a folder called 'for the Open Prolog Additions ƒ' which contains two extra predicates. If you want to use them, drag them into the Open Prolog Additions folder and restart Open Prolog. One predicate is called environment/1, giving information about the Prolog environment, and the other is called debugStartAction/0, called just when a trace begins.
◊ Using Open Prolog
Open Prolog is a text-oriented Prolog. If you have used DEC Prolog or
C-Prolog, then the style of use of Open Prolog is quite similar.
To try to take advantage of Macintosh's great user interface, Open Prolog's user interface is window-oriented rather than line-oriented. To accomplish this effectively, there are a few differences between Open Prolog's interface and, say, C-Prolog's. In particular, the (line oriented) prompts of C-Prolog are moved to the status bar, and you make use of the ENTER key to enter commands and information.
If you haven't done so already, you should go through the beginners tutorial in 'Getting Started'.
◊ Startup
In the standard Macintosh way, you can start Open Prolog
either by opening some of its documents or by opening the application itself.
° Home Folder
A 'Home Folder' is chosen automatically as follows:
If you start Open Prolog by opening some of its documents, then the
folder the documents are in becomes the Home Folder.
If you start Open Prolog by opening it directly, then the folder it's in
becomes the Home Folder.
See the section on File Naming for the significance of the
Home Folder.
° Startup Folder
The Startup Folder is the folder Open Prolog is in when it is launched.
° Additions Folder
The Additions Folder is the folder called 'Open Prolog Additions' that is in the Extensions folder of your System Folder (or in the System Folder if you're using System 6).
° Startup Actions
Before opening any files that you may have selected on the desktop,
Open Prolog will open a Worksheet in the home folder, always called
'Open Prolog Worksheet'.
Open Prolog does a few other things at startup:
It looks in the startup folder, and, if necessary, the additions folder, for a file called 'Open Prolog Options', and if it exists, it is consulted.
It looks in the home folder for a file called 'Open Prolog Startup' and if
it exists, it is consulted.
These files can be used to do routine things at startup, if desired.
Open Prolog Options should contain generally useful stuff, whereas
Open Prolog Startup, being specific to a folder, can contain more specialised
startup stuff.
For example, in this distribution of Open Prolog, a clause in
the Open Prolog Startup file displays an alert message in a box notifying you about the 'Getting Started' document.
So, if this folder happens to be the Home Folder, then the Open Prolog Startup
file will be consulted, and you'll get the alert message.
Once the startup phase is finished, you are free to edit these files in the
normal way - there's nothing special about them.
Note that while Open Prolog Options is being consulted during startup, the default folder for files is the startup or additions folder rather than the home folder.
This facilitates automatic startup with multiple file consultation.
◊ Working with Open Prolog
It helps to visualise the system as having two distinct parts -
the text editor and the Prolog interpreter.
◊ The Text Editor part of Open Prolog
Your interaction with Open Prolog is via the text editor. With it, you can do
text editing things on the Worksheet, and on up to seven other files. You can also issue commands and send information into the Prolog interpreter - see later.
The text-editing facilities offered are standard text editor commands and functions.
Worth mentioning is 'Auto-indent' which, if enabled, works by copying all the spaces & tabs from the start of the previous line down to the start of this line.
Holding down the Option key when typing Return will do the opposite of whatever is selected for auto-indent.
Also worth mentioning is the 'Search All Windows' in the Find and Replace menus:
all windows will be searched, in front-to-back order, until a match is found. The window in which the match is found becomes the front window.
Holding down the Shift key when selecting find or replace will reverse the search direction.
An open diamond - ◊ - appears opposite the name of the current front window
in the Window menu. Underlining indicates that the window needs to be
saved (either it's been changed, or it was never saved before).
The 'Display Selection' menu will scroll the caret or the selected text into
view.
It's possible that Open Prolog won't allow you to open a window because it hasn't
enough memory. To get around this, enter the built-in predicate 'garbage_collect'.
This should free up some space for more windows.
° Window Characteristics
When windows are opened, they are opened in the same location (assuming
it's still visible), and with the same size as when they were last closed.
Likewise, font, font size and the position of the flashing caret or selection
point are remembered from when the window was last used.
A window's maximum size if fixed according to the size of the
printable page in the currently selected printer.
° Locked Files
If a file is locked, or its volume is locked or read only, you can use the
window as normal, but you won't be allowed to save changes to that file.
Locked files have a padlock icon in their window's status bar.
◊ The Interpreter part of Open Prolog
Most of the transactions that occur between you and the Open Prolog interpreter will be through a window, using the Text Editor.
Generally, you issue commands by typing them into a window and then
notifying the interpreter about them using the ENTER key.
Open Prolog writes replies into the same window.
You can use any window for sending commands and for getting replies,
but the Worksheet will be chosen by default or if any errors occur
when using another window.
The Worksheet can't be closed.
◊ The ENTER Key
While you are editing text, the Prolog interpreter is disconnected from
what you are doing - it won't be 'listening'. To get its attention, you need
to notify it in some way that what you're doing is not just text editing.
That is the function of the ENTER key: all input from the text editor to the
Prolog interpreter is denoted by selecting the text and typing the ENTER key.
(This is similar to the arrangement in Apple's excellent MPW).
For example, below is the text of a command to consult the file 'benchmarks'.
To input it to the interpreter, select it (include the full stop) and
type the ENTER key:
[benchmarks].
In practice, you don't always have to select the whole thing - if the text
occupies only one line, position the caret anywhere along the line
and press the ENTER key.
The whole line will then be taken as the text. This is called
'single line selection'.
Remember also that you need to use the ENTER key to denote all input to the
interpreter, not just command input. For example, if your program wants to
read a term from the user, you must type or find the text, select it all,
and press the ENTER key to tell the interpreter to take it as input.
For example, try evaluating the following query by single-line-selecting it.
You'll need to provide a further input in response; again, you
can use single line selection. Also, remember the full stop after
the term:
write('Please enter a Prolog term: '),read(Term),write('It''s: '),write(Term).
As is normal on DEC Prolog, where variable bindings are given as part
of the result of a query, the system waits for confirmation - type the
ENTER key - or a request for a retry - type a semicolon and the ENTER key.
◊ Prompts
The standard ?- prompt generally appears on the 'status bar'
at the top of the front window.
If you wish, you can enter a query preceded by a ?- - it won't make any
difference. If you precede your query by a :- then it will be performed
without returning the variable bindings.
Examples:
:- write(H),nl.
?- write(G).
◊ Comment on ENTER & Prompts
Using the ENTER key to denote input to the interpreter has many advantages,
although it's probably a bit annoying to get used to.
The principal advantage is that, since RETURN does not signify a command or anything special, you can do standard text editing freely and you can use any part of the Worksheet as a source of input.
In other words, you can re-use text on the Worksheet over and over.
(Some people have complained that there isn't an ENTER key of their
machines. In fact, there is one on every machine. Sometimes it has a symbol
like an arrowhead pointing upwards to meet a horizontal line.
On compact keyboards it is usually the strange key to the right of the
space bar.)
◊ Verbose and Terse Answers
Most Prologs answer a query with a 'yes' (after any variable bindings) or a 'no' depending on whether the query can be proved or not.
Open Prolog defaults to this behaviour also - it gives a 'verbose' answer.
If you wish, you can suppress the output of 'yes' and 'no'
by changing the answering mode from verbose to terse. The built-in predicate
to use is 'system$answer$mode'(CurrentAnswerMode,NewAnswerMode).
Allowed arguments are 'terse' or 'verbose'.
The following example determines the current answering mode without
changing it:
'system$answer$mode'(State,State).
◊ Syntax Errors
When Open Prolog tries to read a term - either as a result of your program,
or of built-in predicates like consult - if it detects any errors, it will try to
notify you in a useful way. An error message is written to the output window.
The part of the error message that begins:
:- 'Show Syntax Error'(…
has the form of a Prolog command, and can be used to call the
'Show Syntax Error' built-in predicate,
which will try to open the file and show you where the error was.
You use it by single-line-selecting it.
Try it by consulting the file 'buggy syntax' which has a
deliberate error:
['buggy syntax'].
If the file is too big to open as a window (greater than 32767 bytes), the call will fail.
◊ Activity During Evaluation
During a long evaluation, it's possible to use the
text editor in windows other than the current output window (the current
output window is usually the Worksheet). The system will share
the processor between the interpreter and the text editor.
Generally, you won't notice the sharing being done.
Occasionally, however, the interpreter will keep the processor
for a few seconds to do garbage collection, or I/O.
During that time the text editor will 'freeze' and won't respond to
the keyboard or other user input.
This is normal and is no cause for concern.
Please be careful to save your work frequently in this mode,
because if the evaluation causes Open Prolog to crash,
your work may be lost.
◊ Stopping an Evaluation
The standard 'Command-.' will halt a Prolog evaluation.
◊ Background Operation
Open Prolog is Multifinder friendly and will run in the Multifinder
background. This may be useful for long evaluations. Running under System 7,
it can be hidden and still be running.
◊ Operation on battery powered Macintoshes.
Open Prolog works fine on all battery powered Macintoshes.
One complication regarding battery powered Macs is that
during periods of longer than about 15 seconds without any
user interaction or cursor animation, the machine may go into 'rest' mode.
In this mode, battery power is conserved by running about 15 times slower
than normal.
Open Prolog spins a cursor during long evaluations to prevent resting.
However, if you are text-editing during an evaluation, the cursor will be
the I-beam, and it won't be animated; if you stop typing or moving the mouse
for more than about 15 seconds, then the machine will rest.
◊ Built-In Predicates
To get a list of all predicates - normal, built-in and external,